//
//  YGRootView.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/16.
//

#import "YGRootView.h"
#import "XCMediator+YGLoginModule.h"
#import "YGTabBarViewController.h"
#import "YGSceneManager.h"
#import "YGCacheManager.h"
#import "YGUserInfoModel.h"
@implementation YGRootView

+ (UIViewController *)getRootViewControoler{
    BOOL isLogin = [UserInfoManager shareInstance].isLogin;
    if (isLogin) {
        YGUserInfoType type = [[UserInfoManager shareInstance] getUserType];
        UIViewController *mainTabBar;
        switch (type) {
            case YGUserPatient:
            {
                mainTabBar = [[YGTabBarViewController alloc] init];
            }
                break;

            default:
                break;
        }
        //登录成功
        return mainTabBar;
    }else{
        if ([self checkAutoLogin]) {
            return [self getRootViewControoler];   //  重设数据类型，
        }
        UIViewController *vc = [[XCMediator sharedInstance] getLoginMudule_loginViewController];
        UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];
        
        return navi;
   }
}

+ (void)resetRootViewController{
    
    UIViewController *vc = [self getRootViewControoler];
    [[YGSceneManager shareInstance].window setRootViewController:vc];
}

+ (BOOL)checkAutoLogin{
    NSArray *infos = [[YGCacheManager shareInstance] getUserInfos];
    if (infos.count > 0) {
        YGUserInfoModel *model = [infos firstObject];
        [[UserInfoManager shareInstance] autoLoginWithUserInfo:model];
        return YES;
    }
    return NO;
}

@end
